﻿/********************************************************************************/
// <copyright file="ObjectFactory.cs" company="Asia E-Business Solutions">
//     Copyright © 2012. All right reserved
// </copyright>
//
// <history>
//  <change who="Hieu Nguyen" date="11/12/2012 12:14:55 PM">Created</change>
// <history>
/********************************************************************************/

namespace JLL.China.Infrastructure
{
    using System.Collections.Generic;
    using Microsoft.Practices.Unity;


    /// <summary>
    /// A object factory class which wraps Unity inside
    /// </summary>
    public class ObjectFactory
    {
        #region -- Private Fields --
        public static IUnityContainer Container { get; set; }
        #endregion

        /// <summary>
        /// Resolves this instance.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static T Resolve<T>()
        {
            Check.Ensure(Container != null, "Container has not been set");
            return Container.Resolve<T>();
        }

        /// <summary>
        /// Resolves all.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static IList<T> ResolveAll<T>()
        {
            Check.Ensure(Container != null, "Container has not been set");
            var objects = Container.ResolveAll<T>();
            IList<T> result = new List<T>(objects);
            return result;
        }

        /// <summary>
        /// Resolves the specified name.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        public static T Resolve<T>(string name)
        {
            Check.Ensure(Container != null, "Container has not been set");
            return Container.Resolve<T>(name);
        }
    }
}
